<?php
    global $current_user;
    get_currentuserinfo();
    $security_query = "SELECT ID FROM crm_users WHERE user_login='".$current_user->user_login."'";
    $security_result = mysql_query($security_query);
    while ($security_row = mysql_fetch_array($security_result))
    {
        if ($security_row['ID'] == 1)
        {
            echo '<input value="Новая задача" onclick="location.href=\'/?page_id=40\'" type="button">';
        }
    }
    echo "<table style='font-size: 14px;'>
            <thead>
                <tr>
                    <th>Задача</th>
                    <th>Имя задачи</th>
                    <th>Назначено</th>
                    <th>Статус задачи</th>
                </tr>
            </thead>";
    $query = "SELECT id, title, descr, customer, customer_mail, performer, performer_mail, status FROM crm_orders";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result))
    {
        if ($row['status'] == 0)
        {
            $status = "Новая";
        }
        elseif ($row['status'] == 1)
        {
            $status = "Обрабатывается";
        }
        elseif ($row['status'] == 2)
        {
            $status = "На выполнении";
        }
        elseif ($row['status'] == 3)
        {
            $status = "Обработана";
        }
        elseif ($row['status'] == 4)
        {
            $status = "Закрыта";
        }
        echo "<tbody>
                <tr>
                    <th> ".$row['id']." <a href='/?page_id=51&order=".$row['id']."'>Изменить</a><br/><a href='/?page_id=47&order=".$row['id']."'>Подробнее</a></th>
                    <td>".$row['title']."</td>
                    <td>".$row['performer']."</td>
                    <td>".$status."</td>
                </tr>
              </tbody>";
    }
    echo "</table>";
?>